package com.pocket.demo.base.utils;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.pocket.demo.base.api.PageResult;

import java.util.ArrayList;

public class BeanUtils extends BeanUtil {
    public static <S, T> PageResult<T> toBean(PageResult<S> source, Class<T> targetType) {
        PageResult<T> result = new PageResult<T>();
        if (source == null || CollectionUtil.isEmpty(source.getData())) {
            result.setData(new ArrayList<>());
        } else {
            result.setCurrent(source.getCurrent());
            result.setSize(source.getSize());
            result.setPages(source.getPages());
            result.setTotal(source.getTotal());
            result.setData( copyToList(source.getData(), targetType));
        }
        return result;
    }
}
